package com.dhj.streamTest;

import com.dhj.streamTest.entity.Author;
import com.dhj.streamTest.entity.Book;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;

import static com.dhj.streamTest.entity.AuthorList.getAuthors;

public class Demo10 {

    public static void main(String[] args) {
        List<Author> authors = getAuthors();

        authors.stream().distinct()
                .flatMap(author -> author.getBooks().stream())
                .filter(book -> !"哲学".equals(book.getCategory()))
                .forEach(book -> System.out.println(book.getCategory()));

        System.out.println("---------------------");

        authors.stream().distinct()
                .flatMap(author -> author.getBooks().stream())
                .flatMap(book -> Arrays.stream(book.getCategory().split(",")))
                .distinct()
                .forEach(str -> System.out.println(str));

    }

}
